<?php
// --------------------------------------------------------------------
// database.php
// Database class to manage database operations.
// Tommy Harvey
// 2011-04-02   
// --------------------------------------------------------------------

class Database{
    var $servername = '';
    var $username = '';
    var $password = '';
    var $database = '';
    var $connection = NULL;
    
    function Database($servername, $username, $password)
    {
        $this->servername = $servername;
        $this->username = $username;
        $this->password = $password;
        $this->connection = $this->ConnectDB();
        return ($this->connection);
    }
    
    function ConnectDB()
    {
        $connection = mysql_connect($this->servername, $this->username, $this->password) or die ('Impossible to connect on that server : '.$this->servername);
        return ($connection);
    }
    
    function Query($query)
    {
        $result = mysql_query($query) or die ("Error in the query : <br>".$query. "<br>(". mysql_errno().") ".mysql_error());
        return ($result);
    }
    
    function SelectDB($dbname)
    {
        $this->database = $dbname;
        mysql_select_db($this->database) or die ('Impossible to open the database \''.$this->database.'\''. mysql_error().'\n');
    }
    
    function DisconnectDB () {
        mysql_close($this->connection) or die ('Impossible to close the database connection \''.$this->connection.'\''. mysql_error());
    }
}
?>
